<?php
/**
 * This block depends on Inquiry Status
 */

use Fox\SalesDistribution\Sales;
use Fox\SalesDistribution\Sales\Inquiry\Partner;
use Fox\SalesDistribution\Sales\Partner\Role;
use Fox\SalesDistribution\Sales\Inquiry;
use Fox\Common\Customer;
use Fox\Html\TextArea;
use Fox\Generator,Fox\Html\Wrapper,Fox\Html\DropList;
$status = $params['status'];
$inquiryid =  Xview::instance()->val("inquiryid",$params['inquiryid']) ;
$block = new Fox\Html\Block("bFinal",Msg(Sales::BUNDLE_NAME,31));
switch ($status)
{
	case Inquiry::STATUS_LOST;
		
		$finder = new Customer();
		$res = $finder->find(new Fox\Dao\SqlFragment("pa.inquiryid = ? AND pa.role = ? AND pa.loekz = ? ",
													 array($inquiryid,Role::COMPETITOR,0)
													 ),null,array(Inquiry::$JOIN_CUSTOMERS));
		if(count($res) == 0)
		{
			// Display all known competitors
			$res = $finder->find(new Fox\Dao\SqlFragment("type = ?",array(Customer::TYPE_COMPETITOR)));
		}
		$block->add(new DropList("winnerid",true))
						->options($res,
								  Fox\Generator::useAttribute('customerid'),
								  Fox\Generator::useAttribute('name1'));
	break;
	case Inquiry::STATUS_WIN;
		$finder = new Customer();
		$res = $finder->find(new Fox\Dao\SqlFragment("type = ?",array(Customer::TYPE_US)));
		
		$block->add(new DropList("winnerid",false,true))
						->options($res,
								  Fox\Generator::useAttribute('customerid'),
								  Fox\Generator::useAttribute('name1'));
		$block->add(new Fox\Html\Input("contract_sedate",true));
		$block->add(new Fox\Html\Input("contract_redate"));
	break;
	case Inquiry::STATUS_CANCEL;
		$block->add(new TextArea("cancel_reason",true));
	break;
	default:
		$block = new Wrapper("bFinal");
	break;
}
return $block;